/**
 * 
 */
package sdiff.tests;

import java.text.NumberFormat;

/**
 * Extremely dumb class that just tracks the matching results
 * for chadDiff or ldiff.
 * 
 * TODO: Doesn't track IDs correct and wrong, like Reiss does.
 * Not sure what each of those means, exactly.
 * 
 * @author jspacco
 *
 */
public class ReissScore
{
    private int numCorrectMatches;
    // we matched a line that should have been deleted
    private int numSpuriousDeletes;
    // we deleted a line that should have been matched
    private int numEliminatedDeletes;
    // matched a line to the wrong line
    private int numMismatchedChanges;
    
    public void plus(ReissScore other) {
        this.numCorrectMatches += other.numCorrectMatches;
        this.numSpuriousDeletes += other.numSpuriousDeletes;
        this.numEliminatedDeletes += other.numEliminatedDeletes;
        this.numMismatchedChanges += other.numMismatchedChanges;
    }
    
    public void correctLine() {
        numCorrectMatches++;
    }
    public void spuriousDelete() {
        numSpuriousDeletes++;
    }
    public void eliminatedDelete() {
        numEliminatedDeletes++;
    }
    public void mismatchedChange() {
        numMismatchedChanges++;
    }
    public int getNumIncorrect() {
        return numMismatchedChanges+numEliminatedDeletes+numSpuriousDeletes;
    }
    public int getTotalMatchAttempts() {
        return numCorrectMatches + getNumIncorrect();
    }
    /**
     * @return the numCorrectChanges
     */
    public int getNumCorrectChanges()
    {
        return numCorrectMatches;
    }
    /**
     * @return the numSpuriousDeletes
     */
    public int getNumSpuriousDeletes()
    {
        return numSpuriousDeletes;
    }
    /**
     * @return the numEliminatedDeletes
     */
    public int getNumEliminatedDeletes()
    {
        return numEliminatedDeletes;
    }
    /**
     * @return the numMismatchedChanges
     */
    public int getNumMismatchedChanges()
    {
        return numMismatchedChanges;
    }
    public String toXMLString(String method)
    {
        return toXMLString(method, -1L);
    }
    
    public String toXMLString(String method, long avgTime)
    {
        // TODO Not tracking: IDSWRONG
        return "<SCORE METHOD=\""+method+"\" " +
                "CORRECT=\""+getNumCorrectChanges()+"\" "+
                "CHANGE=\"" +getNumMismatchedChanges()+ "\" " +
                "ELIM=\"" +getNumEliminatedDeletes()+ "\" " +
                "SPURRIOUS=\"" +getNumSpuriousDeletes()+ "\" " +
                "AVGTIME=\"" +avgTime+ "\" " +
                "/>";
    }
    
    private static NumberFormat f=NumberFormat.getPercentInstance();
    public String toStringPercentage() {
        double total=getTotalMatchAttempts();
        StringBuffer buf=new StringBuffer();
        buf.append(f.format(getNumCorrectChanges()/total)+"\t");
        buf.append(f.format(getNumMismatchedChanges()/total)+"\t");
        buf.append(f.format(getNumEliminatedDeletes()/total)+"\t");
        buf.append(f.format(getNumSpuriousDeletes()/total));
        return buf.toString();
    }
    public String toString() {
        StringBuffer buf=new StringBuffer();
        buf.append(getNumCorrectChanges()+"\t");
        buf.append(getNumMismatchedChanges()+"\t");
        buf.append(getNumEliminatedDeletes()+"\t");
        buf.append(getNumSpuriousDeletes());
        return buf.toString();
    }

    /**
     * @param numCorrectMatches the numCorrectMatches to set
     */
    public void setNumCorrectMatches(int numCorrectMatches)
    {
        this.numCorrectMatches = numCorrectMatches;
    }

    /**
     * @param numSpuriousDeletes the numSpuriousDeletes to set
     */
    public void setNumSpuriousDeletes(int numSpuriousDeletes)
    {
        this.numSpuriousDeletes = numSpuriousDeletes;
    }

    /**
     * @param numEliminatedDeletes the numEliminatedDeletes to set
     */
    public void setNumEliminatedDeletes(int numEliminatedDeletes)
    {
        this.numEliminatedDeletes = numEliminatedDeletes;
    }

    /**
     * @param numMismatchedChanges the numMismatchedChanges to set
     */
    public void setNumMismatchedChanges(int numMismatchedChanges)
    {
        this.numMismatchedChanges = numMismatchedChanges;
    }
    
}